package org.monkey4j.suppliers;

import java.util.Collection;
import java.util.Map;

import com.google.common.base.Supplier;

import static com.google.common.collect.Maps.newHashMap;

/**
 * Registry holding a mapping of data types to data type value suppliers. At this point new data types
 * with according {@link Supplier}s can be configured.
 * 
 * @author hillger.t
 */
public final class SupplierRegistry {
	private static final Map<Class<?>, Supplier<? extends Collection<?>>> supplierMap = newHashMap();

	static {
		supplierMap.put(String.class, new StringSupplier());
		supplierMap.put(Integer.class, new IntegerSupplier());
		supplierMap.put(Long.class, new LongSupplier());
	}

	public static void register(Class<?> clazz, Supplier<? extends Collection<?>> command) {
		supplierMap.put(clazz, command);
	}

	public <T> Supplier<? extends Collection<? extends Object>> lookup(Class<T> clazz) {
		return supplierMap.containsKey(clazz) ? supplierMap.get(clazz) : new EmptySupplier();
	}
}
